import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class SendThread extends Thread {
    private String msg;

    private Socket socket;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Socket getSocket() {
        return socket;
    }

    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    public SendThread(Socket socket) {
        this.socket = socket;
    }

    public SendThread(Socket socket, String msg) {
        this.socket = socket;
        this.msg = msg;
    }
    public SendThread() {

    }
    public void run(){
        //传的数据类型不统一，所以使用数据流
        DataOutputStream dataOutputStream;
        try {
            dataOutputStream = new DataOutputStream(socket.getOutputStream());
            while (true) {
                //如果消息不为空
                if (msg != null) {
                    //发送消息
                    dataOutputStream.writeUTF(msg);
                    //消息发送完毕，把消息清空
                    msg = null;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
